package com.bstek.uflo.form.view.common;

import com.bstek.dorado.view.View;
import com.bstek.dorado.web.DoradoContext;
import com.bstek.uflo.form.Constants;
import com.bstek.uflo.form.action.Action;

/**
 * @author Jacky.gao
 * @since 2013年11月15日
 */
public abstract class AbstractButtonBuilder extends AbstractComponentBuilder {
	protected String buildEventScript(View view,Action actionBean,String actionStr,String buttonId){
		StringBuffer sb=new StringBuffer();
		sb.append("var result=view.id(\""+Constants.DATASET+"\").getData().validate();if(result!='ok')return;\n");
		sb.append("view.id(\""+Constants.UPDATE_ACTION+"\").set(\"parameter\",{action:\""+actionStr+"\",buttonId:\""+buttonId+"\"});\n");
		sb.append("dorado.MessageBox.confirm(\"真的要进行"+actionBean.getName()+"操作吗？\",function(){");
		sb.append("var action=view.id(\""+Constants.UPDATE_ACTION+"\");\n");
		sb.append("action.execute(function(){\n");
		sb.append("if(window.parent && window.parent.closeProcessDialog){\n");
		sb.append("window.parent.closeProcessDialog("+DoradoContext.getCurrent().getRequest().getParameter("type")+");\n");
		sb.append("}\n");
		sb.append("});\n");
		sb.append("});");
		return sb.toString();
	}
}
